/******************************************************************************
 * Copyright 2017 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

/**
 * @file
 * @brief Defines the DemoControlTask class.
 */

#pragma once

#include <memory>
#include <string>
#include <vector>

#include "modules/common_msgs/config_msgs/vehicle_config.pb.h"
#include "modules/control/controllers/demo_control_task/proto/demo_control_task_conf.pb.h"

#include "cyber/plugin_manager/plugin_manager.h"
#include "modules/control/control_component/controller_task_base/control_task.h"

/**
 * @namespace apollo::control
 * @brief apollo::control
 */
namespace apollo {
namespace control {

/**
 * @class DemoControlTask
 *
 * @brief DemoControlTask: Set the acceleration to 2 when the vehicle
 * acceleration is less than 3.
 */
class DemoControlTask : public ControlTask {
 public:
  /**
   * @brief constructor
   */
  DemoControlTask();

  /**
   * @brief destructor
   */
  virtual ~DemoControlTask();

  /**
   * @brief initialize DemoControlTask
   * @return Status initialization status
   */
  common::Status Init(std::shared_ptr<DependencyInjector> injector) override;

  /**
   * @brief compute brake / throttle values based on current vehicle status
   *        and target trajectory
   * @param localization vehicle location
   * @param chassis vehicle status e.g., speed, acceleration
   * @param trajectory trajectory generated by planning
   * @param cmd control command
   * @return Status computation status
   */
  common::Status ComputeControlCommand(
      const localization::LocalizationEstimate *localization,
      const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory,
      control::ControlCommand *cmd) override;

  /**
   * @brief stop DemoControlTask
   */
  void Stop() override;

  /**
   * @brief reset demo control task
   * @return Status reset status
   */
  common::Status Reset() override;

  /**
   * @brief DemoControlTask name
   * @return string controller name in string
   */
  std::string Name() const override;

 protected:
  std::shared_ptr<DependencyInjector> injector_;

 private:
  std::string name_;
  double low_bound_acceleration_ = 0.0;
  DemoControlTaskConf demo_control_task_conf_;
};

// 1.2 当前类声明为插件
CYBER_PLUGIN_MANAGER_REGISTER_PLUGIN(apollo::control::DemoControlTask,
                                     ControlTask)

}  // namespace control
}  // namespace apollo
